﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.Cart.ViewModels
{
	public class CartItemViewModel
	{
		public ERPStore.Models.Product Product { get; set; }
		public int Quantity { get; set; }
		public ERPStore.Models.Price CatalogPrice { get; set; }
		public ERPStore.Models.Price SalePrice { get; set; }
		public int SaleUnitValue { get; set; }
		public int Packaging { get; set; }
		public ERPStore.Models.Price RecyclePrice { get; set; }
		public string CouponReason { get; set; }
		public ERPStore.Models.ProductStockInfo ProductStockInfo { get; set; }
		public ERPStore.Models.ShippingType ShippingType { get; set; }
		public double Discount { get; set; }
		public DateTime CreationDate { get; set; }
		public DateTime LastUpdate { get; set; }
		public bool AllowPartialDelivery { get; set; }
		public string OfferName { get; set; }

		#region Totals

		public decimal RecycleTotal
		{
			get
			{
				if (RecyclePrice == null)
				{
					return 0;
				}
				return Quantity * RecyclePrice.Value;
			}
		}
		public decimal RecycleTaxTotal
		{
			get
			{
				if (RecyclePrice == null)
				{
					return 0;
				}
				return Quantity * RecyclePrice.TaxValue;
			}
		}
		public decimal RecycleTotalWithTax
		{
			get
			{
				if (RecyclePrice == null)
				{
					return 0;
				}
				return Quantity * RecyclePrice.ValueWithTax;
			}
		}
		public decimal Total
		{
			get
			{
				return (Quantity * SalePrice.Value) / (SaleUnitValue * 1.0m);
			}
		}

		public decimal CatalogTotal
		{
			get
			{
				return (Quantity * CatalogPrice.Value) / (SaleUnitValue * 1.0m);
			}
		}

		public decimal TotalTax
		{
			get
			{
				return (Quantity * SalePrice.TaxValue) / (SaleUnitValue * 1.0m);
			}
		}

		public decimal TotalWithTax
		{
			get
			{
				return (Quantity * SalePrice.ValueWithTax) / (SaleUnitValue * 1.0m);
			}
		}
		public decimal GrandTotal
		{
			get
			{
				return Total + RecycleTotal;
			}
		}
		public decimal GrandTaxTotal
		{
			get
			{
				return TotalTax + RecycleTaxTotal;
			}
		}
		public decimal GrandTotalWithTax
		{
			get
			{
				return TotalWithTax + RecycleTotalWithTax;
			}
		}

		#endregion

	}
}
